package com.example.service.webhook.business.court.api;

import com.example.service.webhook.api.MoxieClient;
import com.example.service.webhook.business.court.dto.ZhixingCourtCaseDetail;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import retrofit2.Call;
import retrofit2.Response;

import java.io.IOException;
import java.util.List;

/**
 * Created by zouwanli on 17/5/31.
 */
@Component
public class ZhixingCourtClient extends MoxieClient {

    private static final Logger LOGGER = LoggerFactory.getLogger(ZhixingCourtClient.class);

    private ZhixingCourtApi api;

    @Autowired
    public ZhixingCourtClient(@Value("${moxie.api.baseUrl}")String apiBaseUrl,
                              @Value("${moxie.api.token}")String apiToken) {
        super(apiBaseUrl, apiToken);
        api = retrofit.create(ZhixingCourtApi.class);
    }


    public List<ZhixingCourtCaseDetail> getZhixingCourtCaseDetail(String taskId) throws IOException {

        Call<List<ZhixingCourtCaseDetail>> call = api.getCreditInfo(taskId);

        Response<List<ZhixingCourtCaseDetail>> response = call.execute();
        if (response.code() == 200) {
            return response.body();
        } else {
            LOGGER.info("coury getZhixingCourtCaseDetail, status:{}, message:{}", response.code(), response.message());
        }
        return null;

    }

}
